package org.hot100_5.leetcode1;

import java.util.HashMap;

public class Solution {

    public static void main(String[] args) {
        int [] test ={2,7,11,15};
        twoSum(test,9);
    }

    public static int[] twoSum(int[] nums, int target) {
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        int n = nums.length;
        int [] res=  new int[2];

        for (int i = 0; i < n ; i++) {
            hashMap.put(nums[i],i);
        }

        for (int i = 0; i < n; i++) {
            int other =target-nums[i];
            if (hashMap.containsKey(other) && hashMap.get(other)!=i){
                res[0]=i;
                res[1]=hashMap.get(other);
            }
        }

        return res;
    }
}
